﻿using B.S.Packaged.Domain;
using B.S.Packaged.Domain.Tree;
using SqlSugar;

namespace B.S.Packaged.Infra
{
    public class PackagedDbContext
    {


        public SqlSugarClient db { get; }

        public PackagedDbContext()
        {
            db = new SqlSugarClient(new ConnectionConfig()
            {
                DbType = SqlSugar.DbType.MySql,
                ConnectionString = "server=123.57.166.20;port=3306;user=root;password=123456;database=text;",
                IsAutoCloseConnection = true,
                InitKeyType = InitKeyType.Attribute,
            });

            //db.DbMaintenance.CreateDatabase();
            db.CodeFirst.InitTables(typeof(PackagingPlan));
            db.CodeFirst.InitTables(typeof(PackagingPlanDetails));
            db.CodeFirst.InitTables(typeof(RecordsOperations));

            db.CodeFirst.InitTables(typeof(Team));
            db.CodeFirst.InitTables(typeof(WorkSection));
            db.CodeFirst.InitTables(typeof(Report));

            db.CodeFirst.InitTables(typeof(ProductionLine));
            db.CodeFirst.InitTables(typeof(Equipment_Information));
            db.CodeFirst.InitTables(typeof(Workshop));

            db.CodeFirst.InitTables(typeof(CompletedStorage));
            db.CodeFirst.InitTables(typeof(Completedfinished));
            db.CodeFirst.InitTables(typeof(MaterialPreparation));
            db.CodeFirst.InitTables(typeof(MonitorModel));
            db.CodeFirst.InitTables(typeof(PackagingQuality));
            db.CodeFirst.InitTables(typeof(Material));


            db.Aop.OnLogExecuting = (sql, pars) =>
            {
                Console.WriteLine($"执行SQL:{sql},参数:{sql}");
            };
        }
    }
}
